﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using ClassLibrary.DAO;

public partial class Admin_UserControl_ucOrderDetail : System.Web.UI.UserControl
{
    TblOrderDAO orderDAO = new TblOrderDAO(Global.CONNECTION_STRING);
    protected void Page_Load(object sender, EventArgs e)
    {
        string id = Request.QueryString["id"];
        if (!IsPostBack)
        {
            DataTable dt = orderDAO.GetOrder(Global.ConvertToInt(id));
            grdShoppingCart.DataSource = dt;
            grdShoppingCart.DataBind();

            float deliveryfee = 0;
            float total = 0;
            if (dt.Rows.Count > 0)
            {
                deliveryfee = float.Parse(dt.Rows[0]["DeliveryFee"].ToString());
                total = float.Parse(dt.Rows[0]["Total"].ToString());

            }

            lblDeliveryFee.Text = deliveryfee.ToString("0,00.##");
            lblTotal.Text = (total + deliveryfee).ToString("0,00.##");

            lb_address.Text = dt.Rows[0]["Address"].ToString() + '-' + ' ' + dt.Rows[0]["City"].ToString();
            lb_email.Text = dt.Rows[0]["Email"].ToString();
            lb_name.Text = dt.Rows[0]["FirstName"].ToString() + ' ' + dt.Rows[0]["LastName"].ToString();
            lb_OrderDate.Text = dt.Rows[0]["OrderDate"].ToString();
            lb_phone.Text = dt.Rows[0]["Phone"].ToString();

        }

    }
    //protected void btnExport_Click(object sender, EventArgs e)
    //{
    //    string id = Request.QueryString["id"];
    //    DataTable dt = orderDAO.GetOrder(Global.ConvertToInt(id));
    //    HttpContext context = HttpContext.Current;
    //    string attachment = "attachment; filename=Order.xls";
    //    context.Response.ClearContent();
    //    context.Response.AddHeader("content-disposition", attachment);
    //    context.Response.ContentType = "application/vnd.ms-excel";
    //    context.Response.Charset = "UTF-8";
    //    context.Response.ContentEncoding = Encoding.Unicode;

    //    string tab = "";
    //    foreach (DataColumn dc in dt.Columns)
    //    {
    //        Response.Write(tab + dc.ColumnName);
    //        tab = "\t";
    //    }
    //    Response.Write("\n");

    //    int i;
    //    foreach (DataRow dr in dt.Rows)
    //    {
    //        tab = "";
    //        for (i = 0; i < dt.Columns.Count; i++)
    //        {
    //            Response.Write(tab + dr[i].ToString());
    //            tab = "\t";
    //        }
    //        Response.Write("\n");
    //    }

    //    context.Response.BinaryWrite(Encoding.Unicode.GetPreamble());
    //    Response.End();
    //}
    
}
